//
//  YQOrderManageVC.m
//  MuYing
//
//  Created by tbb on 2019/8/1.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "YQOrderManageVC.h"
#import "YQOrderManageListVC.h"
#import "YQIntegralOrderManageListVC.h"
#import <JXCategoryView/JXCategoryView.h>
@interface YQOrderManageVC ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
@property (nonatomic, strong) JXCategoryTitleView * categoryView;
@property (nonatomic, strong) JXCategoryListContainerView * listContainerView;
@property (nonatomic, copy) NSArray * titles;
@end

@implementation YQOrderManageVC

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.type = 0;
    self.isNavShadow = YES;
    if (self.isIntegral) {
        self.navigationItem.title = kYQLS(@"我的积分订单");
    }else{
        self.navigationItem.title = kYQLS(@"我的订单");
    }
    
    self.rightItemImage = YQIMG(@"MY_nav_service_icon");

}

-(void)setupView {
    [super setupView];
    if (self.isIntegral) {
        self.titles = @[kYQLS(@"全部"),kYQLS(@"待付款"),kYQLS(@"待发货"),kYQLS(@"待收货"),kYQLS(@"已完成")];
    }else{
        self.titles = @[kYQLS(@"全部"),kYQLS(@"待付款"),kYQLS(@"待发货"),kYQLS(@"待收货"),kYQLS(@"待评价")];
    }
    self.categoryView = [[JXCategoryTitleView alloc] init];
    self.categoryView.delegate = self;
    self.categoryView.titles = self.titles;
    
    //    self.categoryView.cellSpacing = 82;
    self.categoryView.titleSelectedColor = kAPPThemeColor;
    self.categoryView.titleColor = HexColor(0x989898);
    self.categoryView.titleFont = kSystemMedium(15);
    self.categoryView.titleSelectedFont = kSystemMedium(15);
    self.categoryView.contentEdgeInsetLeft = 12;
    self.categoryView.contentEdgeInsetRight = 12;
    self.categoryView.backgroundColor = UIColor.whiteColor;
    self.categoryView.titleColorGradientEnabled = YES;
    //    self.categoryView.titleLabelZoomEnabled = YES;
    self.categoryView.averageCellSpacingEnabled = YES;
    
    [self.view addSubview:self.categoryView];
    
    self.listContainerView = [[JXCategoryListContainerView alloc] initWithDelegate:self];
    self.listContainerView.defaultSelectedIndex = 0;
    [self.view addSubview:self.listContainerView];
    
    self.categoryView.contentScrollView = self.listContainerView.scrollView;
    self.categoryView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 44);
    self.listContainerView.frame = CGRectMake(0, 44, self.view.bounds.size.width, self.view.bounds.size.height - 44);
    self.categoryView.defaultSelectedIndex = self.type;
    [self.listContainerView didClickSelectedItemAtIndex:self.type];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    
}

#pragma mark - JXCategoryViewDelegate

- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
    [self.listContainerView didClickSelectedItemAtIndex:index];
}

- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
    [self.listContainerView scrollingFromLeftIndex:leftIndex toRightIndex:rightIndex ratio:ratio selectedIndex:categoryView.selectedIndex];
}
#pragma mark - JXCategoryViewDelegate end
#pragma mark - JXCategoryListContainerViewDelegate

- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    if (self.isIntegral) {
        YQIntegralOrderManageListVC *listVC = [[YQIntegralOrderManageListVC alloc] init];
        listVC.type = index;
        [self addChildViewController:listVC];
        return listVC;
    }else{
        YQOrderManageListVC *listVC = [[YQOrderManageListVC alloc] init];
        listVC.type = index;
        [self addChildViewController:listVC];
        return listVC;
    }
}

- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}

#pragma mark - JXCategoryListContainerViewDelegate end

-(void)rightItemAction:(UIButton *)sender {
    
}
@end


